home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / system-tools / tinymeter / source / tinymeter_main / gaugeclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-21  |  22.2 KB  |  808 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/imageclass.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/cghooks.h>
  12. #include <intuition/icclass.h>
  13. #include <intuition/classes.h>
  14. #include <intuition/sghooks.h>
  15. #include <intuition/screens.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/text.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <utility/tagitem.h>
  20. #include <utility/hooks.h>
  21. #include <string.h>
  22. #include "gaugeclass.h"
  23.  
  24. #define col_label       0
  25. #define col_format      1
  26. #define col_base        2
  27. #define col_current     3
  28. #define col_negative    4
  29. #define col_bright      5
  30. #define col_dark        6
  31. #define col_bg          7
  32.  
  33. #define ind_centered    0
  34. #define ind_left        1
  35. #define ind_right       2
  36.  
  37. struct GaugeData
  38. {
  39.     ULONG   min;
  40.     ULONG   max;
  41.     ULONG   current;
  42.     ULONG   base;
  43.     ULONG   old_cur;
  44.     ULONG   old_bas;
  45.     WORD    labelpos;
  46.     UBYTE   fmtind;
  47.  
  48.     ULONG   type;
  49.  
  50.     char    *txtlbl;
  51.     char    *txtfmt;
  52.  
  53.     struct  GAU_Color Colors[GAU_UsedColors];
  54.  
  55.     BOOL    Style3D;
  56.     BOOL    StyleBorder;
  57.     BOOL    StyleBackground;
  58.     BOOL    StyleShadowLabel;
  59.     BOOL    StyleNoGauge;
  60.     BOOL    StyleNoFormat;
  61.     BOOL    StyleNoBase;
  62.  
  63.     struct  TextFont *textFont;
  64.  
  65.     ULONG   Pens[GAU_UsedColors];
  66.     BOOL    PorC[GAU_UsedColors];
  67.  
  68.     BOOL    InitNotDone;
  69.  
  70.     struct  RastPort *nolock_rp;
  71.  
  72.     LONG    histpos,
  73.         oldlgth,
  74.         oldx;
  75.  
  76.     WORD    text_y;
  77.     struct  Locale *locale;
  78.     char    clocktxt[256];
  79.  
  80.     struct  RastPort   *bg_buffer;
  81.     struct  RastPort   *wk_buffer;
  82.     struct  RastPort   *hs_buffer;
  83.  
  84.     WORD    clockpos;
  85.  
  86.     BOOL    highlight;
  87.     WORD    oldclockx;
  88.     WORD    oldclockw;
  89.  
  90.     ULONG   voltype;
  91.     struct  Screen *scr;
  92. };
  93.  
  94. extern ULONG DoSuperMethodA( struct IClass *cl, Object *obj, Msg message );
  95. extern ULONG DoMethod( Object *obj, unsigned long MethodID, ... );
  96. extern ULONG HookEntry();
  97.  
  98. ULONG dispatchGaugeGadget(Class *cl,Object *o, Msg msg);
  99. ULONG newGauge(Class *cl,struct Gadget *g,struct gpRender *msg,struct GaugeData *inst);
  100. ULONG getGauge(Class *cl,struct Gadget *g,struct gpRender *msg);
  101. setGauge(Class *cl,struct Gadget *g,struct gpRender *msg);
  102. ULONG disposeGauge(Class *cl,struct Gadget *g,struct gpRender *msg);
  103. ULONG renderGauge(Class *cl,struct Gadget *g, struct gpRender *msg);
  104.  
  105. __geta4 ULONG dispatchGaugeGadget(Class *cl,Object *o, Msg msg)
  106. {       
  107.     switch( msg->MethodID )
  108.     {
  109.     case    OM_SET:
  110.         setGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
  111.         return(DoSuperMethodA(cl,o,msg));
  112.     case    GM_RENDER:
  113.         return(renderGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
  114.     case    OM_NEW:
  115.         if(o = (Object *)DoSuperMethodA(cl, o, msg) )
  116.              return(newGauge(cl,(struct Gadget *)o,(struct gpRender *)msg,INST_DATA(cl, o)));
  117.         else return(0L);
  118.     case    OM_GET:
  119.         return(getGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
  120.     case    OM_DISPOSE:
  121.         disposeGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
  122.     default:
  123.         return(DoSuperMethodA(cl,o,msg));
  124.     }
  125. }
  126.  
  127. Class *initGaugeGadgetClass(void)
  128. {
  129.     struct IClass *cl;
  130.     if( cl = (struct IClass *)MakeClass( NULL, "gadgetclass", NULL, sizeof(struct GaugeData), 0) )
  131.     {  
  132.     cl->cl_Dispatcher.h_Entry    = HookEntry;
  133.     cl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)dispatchGaugeGadget;
  134.     return((Class *)cl);
  135.     }
  136.     return(0L);
  137. }
  138.  
  139. BOOL freeGaugeGadgetClass( Class *cl )
  140. {
  141.     return FreeClass(cl);
  142. }
  143.  
  144. struct GAU_Color *GetGaugePen(WORD pen)
  145. {
  146.     static struct GAU_Color dummycol={ TRUE, 0, 0, 0 };
  147.     dummycol.red=pen; return(&dummycol);
  148. }
  149.  
  150. ULONG newGauge(Class *cl,struct Gadget *g,struct gpRender *msg,struct GaugeData *inst)
  151. {
  152.     struct   TagItem *ti;
  153.     if(ti = ((struct opSet *)msg)->ops_AttrList)
  154.     {
  155.     if(inst->textFont = (struct TextFont *)GetTagData(GAU_TextFont,OpenTopaz(),ti))
  156.     {
  157.         struct RastPort *dummy;
  158.         if(dummy=(struct RastPort *)AllocVec(sizeof(struct RastPort),0L))
  159.         {
  160.         int     i;
  161.         UWORD   def_pens[]={ 2, 2, 1, 3, 1, 2, 1, 0 };
  162.         ULONG   gau_tags[]={GAU_ColLabel,GAU_ColFormat,GAU_ColBase,GAU_ColCurrent,GAU_ColNegative,GAU_ColBrightEdg,GAU_ColDarkEdg,GAU_ColBackground};
  163.  
  164.         InitRastPort(dummy);
  165.         dummy->Font=inst->textFont;
  166.  
  167.         inst->min               = GetTagData(GAU_Min,        0, ti);
  168.         inst->max               = GetTagData(GAU_Max,    65535L, ti);
  169.         inst->current           = GetTagData(GAU_Current,32162L, ti);
  170.         inst->base              = GetTagData(GAU_Base,   16384L, ti);
  171.         inst->txtfmt            = (char *)GetTagData(GAU_TextFormat, "%td", ti);
  172.         inst->txtlbl            = (char *)GetTagData(GAU_Label, "Gauge", ti);
  173.         inst->labelpos          = GetTagData(GAU_LabelPos,TextLength(dummy,inst->txtlbl,my_strlen(inst->txtlbl))+4, ti);
  174.  
  175.         inst->Style3D           = GetTagData(GAU_3D,  TRUE, ti);
  176.         inst->StyleBorder       = GetTagData(GAU_Border, TRUE, ti);
  177.         inst->StyleBackground   = GetTagData(GAU_Background, FALSE, ti);
  178.         inst->StyleShadowLabel  = GetTagData(GAU_ShadowLabel, FALSE, ti);
  179.         inst->StyleNoGauge      = GetTagData(GAU_NoGauge,   FALSE, ti);
  180.         inst->StyleNoFormat     = GetTagData(GAU_NoFormat,  FALSE, ti);
  181.         inst->StyleNoBase       = GetTagData(GAU_NoBase,  FALSE, ti);
  182.         inst->fmtind            = GetTagData(GAU_FmtIndent, FALSE, ti);
  183.         inst->type              = GetTagData(GAU_Type, GAU_Type_gauge, ti);
  184.         inst->voltype           = GetTagData(GAU_VolType, 0L, ti);
  185.         inst->locale            = ( inst->type==GAU_Type_clock ) ? (struct Locale *)OpenLocale(NULL) : 0L ;
  186.  
  187.         for(i=0;i<GAU_UsedColors;i++) CopyMem(GetTagData(gau_tags[i], GetGaugePen(def_pens[i]),ti),&inst->Colors[i],sizeof(struct GAU_Color));
  188.  
  189.         inst->InitNotDone=TRUE;
  190.         inst->highlight=TRUE;
  191.         inst->oldclockw=0L;
  192.         inst->oldclockx=0L;
  193.  
  194.         FreeVec(dummy);
  195.         return((ULONG)g);
  196.         }
  197.         else return(0L);
  198.     }
  199.     else return(0L);
  200.     }
  201.     else return(0L);
  202. }
  203.  
  204. freeRPorts(struct GaugeData *inst)
  205. {
  206.     if(inst->bg_buffer)
  207.     {
  208.     FreeBitMap(inst->bg_buffer->BitMap);
  209.     FreeVec(inst->bg_buffer);
  210.     inst->bg_buffer=0L;
  211.     }
  212.  
  213.     if(inst->wk_buffer)
  214.     {
  215.     FreeBitMap(inst->wk_buffer->BitMap);
  216.     FreeVec(inst->wk_buffer);
  217.     inst->wk_buffer=0L;
  218.     }
  219.  
  220.     if(inst->hs_buffer)
  221.     {
  222.     FreeBitMap(inst->hs_buffer->BitMap);
  223.     FreeVec(inst->hs_buffer);
  224.     inst->hs_buffer=0L;
  225.     }
  226.  
  227. }
  228.  
  229. ULONG disposeGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  230. {
  231.     int w;
  232.     struct GaugeData *inst=INST_DATA(cl,g);
  233.     CloseLocale(inst->locale);
  234.     for(w=0;w<GAU_UsedColors;w++)FreePenNew(inst->scr,&inst->Colors[w],w,inst->Pens);
  235.     freeRPorts(inst);
  236. }
  237.  
  238. ULONG getGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  239. {
  240.     struct GaugeData *inst=INST_DATA(cl,g);
  241.     switch (((struct opGet *)msg)->opg_AttrID)
  242.     {
  243.     case    GAU_RPBackground:
  244.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->bg_buffer;
  245.         break;
  246.     case    GAU_Base:
  247.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->base;
  248.         break;
  249.     case    GAU_Current:
  250.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->current;
  251.         break;
  252.     default:
  253.         *(((struct opGet *)msg)->opg_Storage)=0L;
  254.         break;
  255.     }
  256.     return((ULONG)TRUE);
  257. }
  258.  
  259. setGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  260. {
  261.     struct TagItem      *ti,*tstate=((struct opSet *)msg)->ops_AttrList;
  262.     struct GaugeData    *inst=INST_DATA(cl,g);
  263.     ULONG  t_data;
  264.  
  265.     while(ti=(struct TagItem *)NextTagItem(&tstate))
  266.     {
  267.     t_data=(ULONG)ti->ti_Data;
  268.     switch(ti->ti_Tag)
  269.     {
  270.         case    GAU_Current:
  271.             inst->current=  (ULONG)t_data;
  272.             break;
  273.         case    GAU_Base:
  274.             inst->base=     (ULONG)t_data;
  275.             break;
  276.         case    GAU_Max:
  277.             inst->max=      (ULONG)t_data;
  278.             break;
  279.         case    GAU_VolType:
  280.             inst->voltype=  (ULONG)t_data;
  281.             break;
  282.     }
  283.     }
  284.     if ( FindTagItem(GA_Width,  ((struct opSet *)msg)->ops_AttrList) ||
  285.      FindTagItem(GA_Height, ((struct opSet *)msg)->ops_AttrList) ||
  286.      FindTagItem(GA_Top,    ((struct opSet *)msg)->ops_AttrList) ||
  287.      FindTagItem(GA_Left,   ((struct opSet *)msg)->ops_AttrList) )
  288.     {
  289.     inst->highlight=TRUE;
  290.     inst->InitNotDone=TRUE;
  291.     freeRPorts(inst);
  292.     }
  293. }
  294.  
  295. char *formattext(ULONG current, ULONG base, ULONG max, char format[], ULONG special, char *temp_str)
  296. {
  297.     int         i=0,
  298.         j=0;
  299.     char        temp_str_1[64];
  300.     BOOL        negative;
  301.  
  302.     while(format[i]!=0)
  303.     {
  304.     if(format[i]=='%')
  305.     {
  306.         ULONG   dummy=0;
  307.         UBYTE   dummy_2=0,
  308.             dummy_1=0,
  309.             dummy_3=0;
  310.         i++;
  311.         if(format[i]=='t'){dummy_2=1;i++;}
  312.         if(format[i]=='T'){dummy_2=4;i++;}
  313.         if(format[i]=='k'){dummy_1=1;i++;}
  314.         if(format[i]=='m'){dummy_1=2;i++;}
  315.         if(format[i]=='o'){dummy_3=1;i++;}
  316.         if(format[i]=='%'){dummy_2=3;i++;}
  317.         switch(format[i])
  318.         {
  319.         case    'd':
  320.             dummy=current;
  321.             negative=FALSE;
  322.             break;
  323.         case    'b':
  324.             dummy=base;
  325.             negative=FALSE;
  326.             break;
  327.         case    'f':
  328.             dummy   = base<current ? current-base   : base-current;
  329.             negative= base<current ? TRUE           : FALSE;
  330.             break;
  331.         case    'a':
  332.             dummy=max;
  333.             negative=FALSE;
  334.             break;
  335.         case    'p':
  336.             dummy_2=2; dummy=current;
  337.             negative=FALSE;
  338.             break;
  339.         case    'v':
  340.             dummy_2=5;
  341.             break;
  342.         default:
  343.             goto noforward;
  344.             break;
  345.         }
  346.         i++;
  347. noforward:
  348.         if(dummy_3==1)dummy=max-dummy;
  349.         if(dummy_1==1)dummy=dummy>>10;
  350.         if(dummy_1==2)dummy=dummy>>20;
  351.         switch(dummy_2)
  352.         {
  353.         case    4:
  354.             dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],'.',negative);
  355.             for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
  356.             break;
  357.         case    1:
  358.             dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],',',negative);
  359.             for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
  360.             break;
  361.         case    2:
  362.             dummy_2=0;
  363.             if(negative) sprintf(&temp_str_1[0],"-%ld",(((dummy>>8)*100)/((max>>8)+1)));
  364.             else         sprintf(&temp_str_1[0],"%ld", (((dummy>>8)*100)/((max>>8)+1)));
  365.             while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
  366.             break;
  367.         case    0:
  368.             dummy_2=0;
  369.             if(negative) sprintf(&temp_str_1[0],"-%ld",dummy);
  370.             else         sprintf(&temp_str_1[0],"%ld", dummy);
  371.             while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
  372.             break;
  373.         case    3:
  374.             temp_str[j++]='%';
  375.             break;
  376.         case    5:
  377.             if(special&0xFF000000)temp_str[j++]=(char)((special>>24)&0xFF);
  378.             if(special&0x00FF0000)temp_str[j++]=(char)((special>>16)&0xFF);
  379.             if(special&0x0000FF00)temp_str[j++]=(char)((special>>8) &0xFF);
  380.             temp_str[j++]='\\';
  381.             temp_str[j++]=(char)( special     &0xFF)+0x30;
  382.             break;
  383.         }
  384.     }
  385.     else temp_str[j++]=format[i++];
  386.     }
  387.     temp_str[j++]=0;
  388.     return(temp_str);
  389. }
  390.  
  391. __geta4 putChar_hook(struct Hook *hook,struct Locale *locale,ULONG thechar)
  392. {
  393.     struct GaugeData *data;   
  394.     data=(struct GaugeData *)hook->h_Data;
  395.     data->clocktxt[data->clockpos++]=(UBYTE)(thechar);
  396. }
  397.  
  398. struct Hook putCharHook = { { 0,0 },(void *)HookEntry,(void *)putChar_hook, NULL };
  399.  
  400. char *getSTR(struct GaugeData *inst)
  401. {
  402.     static const char *errstr[]=
  403.     {
  404.     "Disk is busy",
  405.     "Not mounted",
  406.     "No disk present",
  407.     "Disk unreadable",
  408.     "No DOS format",
  409.     "n.a.",
  410.     "Kickstart disk"
  411.     };
  412.     switch (inst->current-inst->max)
  413.     {
  414.     case    GAU_err_busy:
  415.         return( errstr[0]);
  416.     case    GAU_err_notmount:
  417.         return( errstr[1]);
  418.     case    GAU_err_notpresent:
  419.         return( errstr[2]);
  420.     case    GAU_err_unreadable:
  421.         return( errstr[3]);
  422.     case    GAU_err_nodos:
  423.         return( errstr[4]);
  424.     case    GAU_err_notavail:
  425.         return( errstr[5]);
  426.     case    GAU_err_kickstart:
  427.         return( errstr[6]);
  428.         break;
  429.     default:
  430.         return(formattext(inst->current,inst->base,inst->max,inst->txtfmt,inst->voltype,inst->clocktxt));
  431.     }
  432. }
  433.  
  434. ULONG renderGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  435. {
  436.     struct  RastPort    *rp;
  437.     struct  BitMap      *work_bm;
  438.     struct  RastPort    *wk_rp,*bg_rp,*hs_rp;
  439.     struct  GaugeData   *inst=INST_DATA(cl,g);
  440.     struct  DateStamp   d_stamp;
  441.     WORD                text_x,w,h;
  442.     WORD                x1,x2,g_x,g_size,g_height,t_length;
  443.     char                *fmt;
  444.     LONG                max;
  445.  
  446.     if(rp = ( msg->MethodID == GM_RENDER ) ? msg->gpr_RPort : (struct RastPort *) ObtainGIRPort(msg->gpr_GInfo) )
  447.     {
  448.     inst->scr=msg->gpr_GInfo->gi_Screen;
  449.     if(inst->InitNotDone)
  450.     {
  451.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,rp->BitMap))
  452.         {
  453.         if(inst->bg_buffer=(struct RastPort *)AllocVec(sizeof(struct RastPort),0L))
  454.         {
  455.             InitRastPort(inst->bg_buffer);
  456.             inst->bg_buffer->BitMap=work_bm;
  457.  
  458.             my_Blit(rp,g->LeftEdge,g->TopEdge,inst->bg_buffer,0,0,g->Width,g->Height);
  459.         }
  460.         else
  461.         {
  462.             FreeBitMap(work_bm);
  463.             return(0L);
  464.         }
  465.         }
  466.         else return(0L);
  467.  
  468.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->bg_buffer->BitMap))
  469.         {
  470.         if(inst->wk_buffer=(struct RastPort *)AllocVec(sizeof(struct RastPort),0L))
  471.         {
  472.             InitRastPort(inst->wk_buffer);
  473.             inst->wk_buffer->BitMap=work_bm;
  474.  
  475.             inst->text_y=((g->Height-((inst->textFont->tf_Baseline+inst->textFont->tf_YSize)>>1))>>1);
  476.             if(inst->textFont->tf_Baseline<inst->textFont->tf_YSize)
  477.             {
  478.             inst->text_y+=inst->textFont->tf_Baseline-1;
  479.             if(inst->text_y<inst->textFont->tf_Baseline)inst->text_y=inst->textFont->tf_Baseline;
  480.             }
  481.             else
  482.             {
  483.             inst->text_y+=inst->textFont->tf_YSize-1;
  484.             if(inst->text_y<inst->textFont->tf_YSize)   inst->text_y=inst->textFont->tf_YSize;
  485.             }
  486.  
  487.             SetDrMd(inst->wk_buffer,JAM1);
  488.             SetFont(inst->wk_buffer,inst->textFont);
  489.         }
  490.         else
  491.         {
  492.             FreeBitMap(work_bm);
  493.             return(0L);
  494.         }
  495.         }
  496.         else return(0L);
  497.  
  498.         for(w=0;w<GAU_UsedColors;w++)GetPenNew(msg,&inst->Colors[w],w,inst->PorC,inst->Pens);
  499.  
  500.         if(inst->type==GAU_Type_histmeter)
  501.         {
  502.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->wk_buffer->BitMap))
  503.         {
  504.             if(inst->hs_buffer=(struct RastPort *)AllocVec(sizeof(struct RastPort),0L))
  505.             {
  506.             inst->histpos=0;
  507.             InitRastPort(inst->hs_buffer);
  508.             inst->hs_buffer->BitMap=work_bm;
  509.             SetAPen(inst->hs_buffer,inst->Pens[col_bg]);
  510.             if(inst->StyleBackground)
  511.             {
  512.                 my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,g->Width,g->Height);
  513.             }
  514.             else
  515.             {
  516.                 my_RectFill(inst->hs_buffer,0,0,g->Width,g->Height);
  517.             }
  518.             }
  519.             else
  520.             {
  521.             FreeBitMap(work_bm);
  522.             return(0L);
  523.             }
  524.         }
  525.         else return(0L);
  526.         }
  527.         inst->old_cur=-1;
  528.         inst->old_bas=-1;
  529.         inst->InitNotDone=FALSE;
  530.     }
  531.  
  532.     wk_rp=inst->wk_buffer;
  533.     bg_rp=inst->bg_buffer;
  534.     switch (inst->type)
  535.     {
  536.         case    GAU_Type_gauge:
  537.             w=g->Width;
  538.             h=g->Height;
  539.             max=inst->max>>8;
  540.             if((inst->current!=inst->old_cur)||(inst->base!=inst->old_bas))
  541.             {
  542.             inst->old_cur=inst->current;
  543.             inst->old_bas=inst->base;
  544.             if(inst->highlight)
  545.             {
  546.                 SetDrMd(rp,JAM1);
  547.                 SetFont(rp,inst->textFont);
  548.                 if(inst->StyleBorder)draw_border_new(rp,inst->labelpos+g->LeftEdge,g->TopEdge,w-inst->labelpos,g->Height,inst->Pens[col_dark],inst->Pens[col_bright]);
  549.                 if(inst->StyleShadowLabel)
  550.                 {
  551.                 SetAPen(rp,inst->Pens[col_dark]);
  552.                 Move(rp,1+g->LeftEdge,inst->text_y+1+g->TopEdge);
  553.                 Text(rp,inst->txtlbl,my_strlen(inst->txtlbl));
  554.                 }
  555.                 SetAPen(rp,inst->Pens[col_label]);
  556.                 Move(rp,g->LeftEdge,inst->text_y+g->TopEdge);
  557.                 Text(rp,inst->txtlbl,my_strlen(inst->txtlbl));
  558.                 inst->highlight=FALSE;
  559.             }
  560.  
  561.             g_x=1+inst->labelpos;
  562.             g_size=w-inst->labelpos-2;
  563.             g_height=h-2;
  564.             my_Blit(bg_rp,g_x,1,wk_rp,g_x,1,g_size,g_height);
  565.  
  566.             if((!inst->StyleNoGauge)&&(inst->current<inst->max))
  567.             {
  568.                 x1=g_size-(WORD)(((inst->base>>8)   *g_size)/((max)==0 ? 1 : (max)));
  569.                 x2=g_size-(WORD)(((inst->current>>8)*g_size)/((max)==0 ? 1 : (max)));
  570.  
  571.                 if(!inst->StyleNoBase)
  572.                 {
  573.                 if(x1<x2)
  574.                 {
  575.                     SetAPen(wk_rp,inst->Pens[col_base]);
  576.                     my_RectFill(wk_rp,g_x,1,x1,g_height);
  577.                     SetAPen(wk_rp,inst->Pens[col_current]);
  578.                     my_RectFill(wk_rp,g_x+x1,1,x2-x1,g_height);
  579.  
  580.                     if(!inst->StyleBackground)
  581.                     {
  582.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  583.                     my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
  584.                     }
  585.                     if(inst->Style3D)
  586.                     {
  587.                     if(x1>1)   draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  588.                     if(x2-x1>1)draw_border_new(wk_rp,g_x+x1,1,x2-x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  589.                     }
  590.                 }
  591.                 else if(x1>x2)
  592.                 {
  593.                     SetAPen(wk_rp,inst->Pens[col_base]);
  594.                     my_RectFill(wk_rp,g_x,1,x2,g_height);
  595.                     SetAPen(wk_rp,inst->Pens[col_negative]);
  596.                     my_RectFill(wk_rp,g_x+x2,1,x1-x2,g_height);
  597.  
  598.                     if(!inst->StyleBackground)
  599.                     {
  600.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  601.                     my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
  602.                     }
  603.                     if(inst->Style3D)
  604.                     {
  605.                     if(x2>1)   draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  606.                     if(x1-x2>1)draw_border_new(wk_rp,g_x+x2,1,x1-x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  607.                     }
  608.                 }
  609.                 else
  610.                 {
  611.                     SetAPen(wk_rp,inst->Pens[col_base]);
  612.                     my_RectFill(wk_rp,g_x,1,x1,g_height);
  613.  
  614.                     if(!inst->StyleBackground)
  615.                     {
  616.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  617.                     my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
  618.                     }
  619.                     if((inst->Style3D)&&(x1>1))draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  620.                 }
  621.                 }
  622.                 else
  623.                 {
  624.                 SetAPen(wk_rp,inst->Pens[col_current]);
  625.                 my_RectFill(wk_rp,g_x,1,x2,g_height);
  626.                 if(!inst->StyleBackground)
  627.                 {
  628.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  629.                     my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
  630.                 }
  631.                 if(inst->Style3D) draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  632.                 }
  633.             }
  634.  
  635.             if(!inst->StyleNoFormat)
  636.             {
  637.                 fmt=getSTR(inst);
  638.                 SetAPen(wk_rp,inst->Pens[col_format]);
  639.                 t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
  640.                 if(t_length<(w-inst->labelpos-1))
  641.                 {
  642.                 switch(inst->fmtind)
  643.                 {
  644.                     case    ind_centered:
  645.                         text_x=g_x+((g_size-t_length)>>1);
  646.                         break;
  647.                     case    ind_left:
  648.                         text_x=g_x+2;
  649.                         break;
  650.                     case    ind_right:
  651.                         text_x=w-t_length-3;
  652.                         break;
  653.                 }
  654.                 Move(wk_rp,text_x,inst->text_y);
  655.                 Text(wk_rp,fmt,my_strlen(fmt));
  656.                 }
  657.             }
  658.  
  659.             my_Blit(wk_rp,g_x,1,rp,g->LeftEdge+g_x,1+g->TopEdge,g_size,g_height);
  660.             }
  661.             break;
  662.         case    GAU_Type_histmeter:
  663.             max=inst->max>>8;
  664.             w=g->Width;
  665.             h=g->Height;
  666.             g_size=h-1;
  667.             hs_rp=inst->hs_buffer;
  668.             if((!inst->StyleNoGauge)&&(inst->current<inst->max))
  669.             {
  670.             x1=(WORD)(((inst->base   >>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
  671.             x2=(WORD)(((inst->current>>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
  672.             inst->histpos++;
  673.             if(inst->histpos>w-3)
  674.             {
  675.                 WORD dummy;
  676.                 dummy=w-(w>>1)-2;
  677.                 SetAPen(hs_rp,inst->Pens[col_bg]);
  678.                 if(inst->StyleBackground)
  679.                 {
  680.                 my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,w,h);
  681.                 my_Blit(inst->bg_buffer,0,0,rp,g->LeftEdge,g->TopEdge,w,h);
  682.                 }
  683.                 else
  684.                 {
  685.                 RectFill(hs_rp,dummy,0,w,h);
  686.                 }
  687.                 inst->histpos=0L;
  688.             }
  689.             if(!inst->StyleNoBase)
  690.             {
  691.                 SetAPen(hs_rp,inst->Pens[col_base]);
  692.                 if(x1>x2)
  693.                 {
  694.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  695.                 SetAPen(hs_rp,inst->Pens[col_current]);
  696.                 RectFill(hs_rp,inst->histpos,x2,inst->histpos,x1);
  697.                 }
  698.                 else if(x1<x2)
  699.                 {
  700.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  701.                 SetAPen(hs_rp,inst->Pens[col_negative]);
  702.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,x2);
  703.                 }
  704.                 else
  705.                 {
  706.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  707.                 }
  708.             }
  709.             else
  710.             {
  711.                 SetAPen(hs_rp,inst->Pens[col_current]);
  712.                 RectFill(hs_rp,inst->histpos,x2,inst->histpos,g_size);
  713.             }
  714.             my_Blit(hs_rp,0,0,wk_rp,0,0,w,h);
  715.             my_Blit(inst->bg_buffer,inst->histpos,0,rp,inst->histpos+g->LeftEdge,g->TopEdge,1,h-1);
  716.             my_Blit(wk_rp,inst->histpos,0,rp,inst->histpos+g->LeftEdge,g->TopEdge,1,h-1);
  717.             }
  718.             if(inst->StyleBorder)draw_border_new(rp,g->LeftEdge,g->TopEdge,w,h,inst->Pens[col_dark],inst->Pens[col_bright]);
  719.             if(!inst->StyleNoFormat)
  720.             {
  721.             fmt=getSTR(inst);
  722.             SetAPen(wk_rp,inst->Pens[col_format]);
  723.             t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
  724.             if(t_length<w)
  725.             {
  726.                 switch(inst->fmtind)
  727.                 {
  728.                 case    ind_centered:
  729.                     text_x=((w-t_length)>>1);
  730.                     break;
  731.                 case    ind_left:
  732.                     text_x=2;
  733.                     break;
  734.                 case    ind_right:
  735.                     text_x=w-t_length-2;
  736.                     break;
  737.                 }
  738.                 Move(wk_rp,text_x,h-3);
  739.                 Text(wk_rp,fmt,my_strlen(fmt));
  740.                 if((inst->oldlgth>t_length)||(inst->oldx<text_x))
  741.                 {
  742.                 my_Blit(wk_rp,inst->oldx,h-1-inst->textFont->tf_YSize,rp,inst->oldx+g->LeftEdge,g->TopEdge+(h-1-inst->textFont->tf_YSize),inst->oldlgth,inst->textFont->tf_YSize);
  743.                 }
  744.                 else
  745.                 {
  746.                 my_Blit(wk_rp,text_x,h-1-inst->textFont->tf_YSize,rp,text_x+g->LeftEdge,g->TopEdge+(h-1-inst->textFont->tf_YSize),t_length,inst->textFont->tf_YSize);
  747.                 }
  748.                 inst->oldlgth=t_length;
  749.                 inst->oldx=text_x;
  750.             }
  751.             }
  752.             break;
  753.         case    GAU_Type_clock:
  754.             w=g->Width-1;
  755.             h=g->Height;
  756.             DateStamp(&d_stamp);
  757.             inst->clockpos=0; putCharHook.h_Data=inst; FormatDate(inst->locale,inst->txtfmt,&d_stamp,&putCharHook);
  758.             if((t_length=TextLength(wk_rp,&inst->clocktxt[0],my_strlen(&inst->clocktxt[0])))<w)
  759.             {
  760.             switch(inst->fmtind)
  761.             {
  762.                 case    ind_centered:
  763.                     text_x=(w-t_length)>>1;
  764.                     break;
  765.                 case    ind_left:
  766.                     text_x=0;
  767.                     break;
  768.                 case    ind_right:
  769.                     text_x=w-t_length-1;
  770.                     break;
  771.             }
  772.             if(inst->oldclockw>t_length)
  773.             {
  774.                 my_Blit(bg_rp,inst->oldclockx,0,wk_rp,inst->oldclockx,0,inst->oldclockw,h);
  775.             }
  776.             else
  777.             {
  778.                 my_Blit(bg_rp,text_x,0,wk_rp,text_x,0,t_length,h);
  779.             }
  780.             if(inst->StyleShadowLabel)
  781.             {
  782.                 SetAPen(wk_rp,inst->Pens[col_dark]);
  783.                 Move(wk_rp,text_x+1,inst->text_y+1);
  784.                 Text(wk_rp,&inst->clocktxt[0],my_strlen(&inst->clocktxt[0]));
  785.             }
  786.             SetAPen(wk_rp,inst->Pens[col_format]);
  787.             Move(wk_rp,text_x,inst->text_y);
  788.             Text(wk_rp,&inst->clocktxt[0],my_strlen(&inst->clocktxt[0]));
  789.             if(inst->oldclockw>t_length)
  790.             {
  791.                 my_Blit(wk_rp,inst->oldclockx,0,rp,g->LeftEdge+inst->oldclockx,g->TopEdge,inst->oldclockw,h);
  792.             }
  793.             else
  794.             {
  795.                 my_Blit(wk_rp,text_x,0,rp,g->LeftEdge+text_x,g->TopEdge,t_length,h);
  796.             }
  797.             inst->oldclockx=text_x;
  798.             inst->oldclockw=t_length;
  799.             }
  800.             break;
  801.     }
  802.     if(msg->MethodID !=GM_RENDER) ReleaseGIRPort(rp);
  803.     return(TRUE);
  804.     }
  805.     else return(FALSE);
  806. }
  807.  
  808.